<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        {include file="public/header"}
    </head>
    
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <!-- <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a> -->
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <!-- <form class="layui-form layui-col-space5">
                                
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="搜索姓名/手机号" name="search_name">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach" type="button">
                                      <i class="layui-icon">&#xe615;</i>
                                    </button>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="excel" type="button">导出数据</button>
                                </div>
                            </form> -->
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table" id="data-table" lay-filter="data-table">
                                
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
	<script type="text/html" id="state">
	    {{# if(d.state=='0'){ }}
	    禁用
	    {{# }else{ }}
	    正常
	    {{# } }}
	</script>
  <script type="text/html" id="avatar">
      <img src="{{d.avatar}}" style="width: 50px;height: 50px">
  </script>
	<script type="text/html" id="message_state">
	    {{# if(d.message_state=='0'){ }}
	    不审核
	    {{# }else{ }}
	    审核
	    {{# } }}
	</script>
	<script type="text/html" id="topBtn">
	    <button type="button" class="layui-btn  layui-btn-sm" onclick="xadmin.open('添加角色','{:url('user/addRole')}', 600,300)">添加角色</button>
	</script>
    <script type="text/html" id="barDemo">
	  <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
	</script>
    <script>
        layui.use(['table', 'util', 'form'], function(){
          var table = layui.table, util= layui.util, form = layui.form;
          //第一个实例
          var data_table = table.render({
            elem: '#data-table'
            ,toolbar: '#topBtn'
            ,url: '{:url('user/roleList')}' //数据接口
            ,page: true
            ,cols: [[ //表头
               {field:  'id', title: 'ID',  fixed: 'left', width:80}
              ,{field:  'name', title: '角色名'}
              ,{field: 'state', title: '状态', templet:'#state'}
              ,{field: 'c_time', title: '创建时间' ,templet:function(d){return util.toDateString(d.commPosttime*1000, "yyyy-MM-dd HH:mm:ss");}}
              ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,limit: 15
          });

          //搜索
          form.on('submit(sreach)', function(data){
            data_table.reload({ page: {page: 1},where: data.field});
          });

          //导出
          form.on('submit(excel)', function(data){
              window.location.href = "{:url('user/userList')}?search_name="+data.field.search_name+'&excel=1';
          });

          table.on('tool(data-table)', function(obj) {
              var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗？', function(index){
                    $.post('{:url('user/delUser')}',{uid:data.id},function(res)
                    {
                        if(res.code == 200)
                        {
                            obj.del();
                            layer.close(index);
                        }else{
                            layer.msg(res.msg);
                            return false;
                        }
                    })
                })
            }else if(obj.event === 'edit'){
                xadmin.open('编辑用户','{:url('user/editUser')}?id='+data.id, 600, 800)
                return false;
            }

          })
          
        });
    </script>
</html>